import { request } from 'ice';

interface IState {
  name: string;
  department: string;
  avatar: string;
  userid: number | null;
  mail: string;
}

export default {
  state: {
    name: 'default',
    department: 'xxx',
    avatar: 'http://cdn.image.lihuacats.com/images/2020/01/12/407DAD58-5A59-4CBB-AB13-CAB50C582A69.th.jpg',
    userid: null,
    mail: 'default@mail.com',
  },

  effects: (dispatch) => ({
    async fetchUserProfile() {
      const res = await request('/profile');
      dispatch.user.update(res);
    },
  }),

  reducers: {
    update(prevState: IState, payload: IState) {
      return { ...prevState, ...payload };
    },
  },
};
